package main

import (
	"fmt"
	"github.com/redis/go-redis/v9"
	"math/rand"
	"reflect"
	"time"
	"wztest/gocelery2"
)

func main() {
	rdb := redis.NewClient(&redis.Options{
		Addr:     "localhost:6379",
		Password: "123456",
		DB:       0,
	})

	// initialize celery client
	cli, _ := gocelery2.NewCeleryClient(
		gocelery2.NewRedisBroker(rdb),
		&gocelery2.RedisCeleryBackend{rdb},
		1,
	)

	// prepare arguments
	taskName := "worker.add"
	argA := rand.Intn(10)
	argB := rand.Intn(10)

	// run task
	asyncResult, err := cli.Delay(taskName, argA, argB)
	if err != nil {
		panic(err)
	}

	// get results from backend with timeout
	res, err := asyncResult.Get(10 * time.Second)
	if err != nil {
		panic(err)
	}

	fmt.Printf("result: %+v of type %+v", res, reflect.TypeOf(res))
}
